package utils;

import org.joda.time.LocalDate;

import android.app.Dialog;
import android.app.DialogFragment;
import android.app.DatePickerDialog;
import android.os.Bundle;
import android.widget.DatePicker;
import android.widget.TextView;

public class LocalDatePickerDialogFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener{
	
	private TextView displayTextView;
	
	public LocalDatePickerDialogFragment(TextView targetDisplay){
		displayTextView=targetDisplay;
	}
	
	@Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {

		LocalDate hoy=new LocalDate();
		int day=hoy.getDayOfMonth();
		int month=hoy.getMonthOfYear()-1;		//Android cuenta los meses desde 0 >.<
		int year=hoy.getYear();
		
        return new DatePickerDialog(getActivity(), this, year, month, day); 
    }

	@Override
	public void onDateSet(DatePicker picker, int year, int month, int day) {
		int jodaMonth=month+1;		//Android cuenta los meses desde 0 >.<
		displayTextView.setText(day+"/"+jodaMonth+"/"+year);
	}

}
